package com.hly.musicbackground.model.admin.rest;

import com.hly.musicbackground.filter.AuthRoot;
import com.hly.musicbackground.model.admin.service.AdminHomeService;
import com.hly.musicbackground.model.user.service.UserLogService;
import com.hly.musicbackground.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 管理端首页
 * */
@RestController
@RequestMapping("/api/admin/home")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "管理端首页")
public class AdminHomeController {

    private final AdminHomeService adminHomeService;
    private final UserLogService userLogService;

    @GetMapping("/home")
    @AuthRoot
    @ApiOperation(value = "获取首页数据")
    public Result getIndex(){
        return Result.ok(adminHomeService.getIndexData());
    }

    @GetMapping("/bar")
    @AuthRoot
    @ApiOperation(value = "获取日期的用户日志饼图")
    public Result bar(@RequestParam(value = "day", defaultValue = "1") int day,
                      @RequestParam(value = "month", defaultValue = "10") int month,
                      @RequestParam(value = "limit", defaultValue = "10") int limit){
        return Result.ok(userLogService.getActiveUserList(day, month, limit));
    }

    @GetMapping("/line")
    @AuthRoot
    @ApiOperation(value = "获取一段时间的活跃曲线")
    public Result line(@RequestParam(value = "time", defaultValue = "1") int time,
                      @RequestParam(value = "b", defaultValue = "false") boolean b){
        return Result.ok(userLogService.getDateActive(time, b));
    }

}
